package com.example.xcspringboot_one.controller;

import com.example.xcspringboot_one.pojo.Book;
import com.example.xcspringboot_one.service.impl.BookServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiaoChen
 * @description: AUTO GENERATION
 * @date 2022/4/24 12:32
 */
@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    BookServiceImpl bookService;

    @PostMapping("/save")
    public String save(@RequestBody Book book) {
        return bookService.save(book);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Integer id) {
        bookService.deleteById(id);
    }

    @PutMapping("/update")
    public String update(@RequestBody Book book) {
        return bookService.update(book);
    }

    @GetMapping("/findById/{id}")
    public Book findById(@PathVariable("id") Integer id) {
        return bookService.findById(id);
    }

    @GetMapping("/findAll/{page}/{size}")
    public Page<Book> findAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return bookService.findAll(page, size);
    }


}
